package com.huabo.contract.service.impl;

import com.hbfk.util.PageInfo;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.oracle.entity.TblLegalLitigationsettlement;
import com.huabo.contract.oracle.mapper.TblLegalLitigationsettlementMapper;
import com.huabo.contract.service.TblLegalLitigationsettlementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class TblLegalLitigationsettlementServiceImpl implements TblLegalLitigationsettlementService {

    @Resource
    private TblLegalLitigationsettlementMapper tblLegalLitigationsettlementMapper;

    @Override
    public void findListByPageInfo(PageInfo<TblLegalLitigationsettlement> pageInfo, TblLegalLitigationsettlement litigation,Integer disputeid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalLitigationsettlementMapper.findListByPageInfo(pageInfo, litigation, disputeid));
            pageInfo.setTotalRecord(tblLegalLitigationsettlementMapper.findListByPageInfoCount(litigation, disputeid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalLitigationsettlementMapper.findListByPageInfo(pageInfo, litigation, disputeid));
            pageInfo.setTotalRecord(tblLegalLitigationsettlementMapper.findListByPageInfoCount(litigation, disputeid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        }
    }

    @Override
    public TblLegalLitigationsettlement findById(Integer litigationId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return this.tblLegalLitigationsettlementMapper.findById(litigationId);
        } else {
            return this.tblLegalLitigationsettlementMapper.findById(litigationId);
        }
    }

    @Override
    public void addLitigationSettlement(TblLegalLitigationsettlement litigation) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
//        if (attids != null && !"".equals(attids)) {
//            List<TblAttachment> attList = new ArrayList(0);
//            String[] attid = attids.split(",");
//            TblAttachment att = null;
//            String[] var6 = attid;
//            int var7 = attid.length;
//
//            for(int var8 = 0; var8 < var7; ++var8) {
//                String id = var6[var8];
//                att = new TblAttachment();
//                att.setAttid(new BigDecimal(id));
//                attList.add(att);
//            }
//
//            litigation.setAttList(attList);
//        }

            this.tblLegalLitigationsettlementMapper.saveLitigationSettlement(litigation);
        } else {
            this.tblLegalLitigationsettlementMapper.saveLitigationSettlement(litigation);
        }
    }

//    @Override
//    public void insertAttRelation(Integer litigationid, String id) {
//        this.tblLegalLitigationsettlementMapper.insertAttRelation(litigationid,id);
//    }

    @Override
    public void updateModifyLitigationSettlement(TblLegalLitigationsettlement oldLitigation) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblLegalLitigationsettlementMapper.updateModifyLitigationSettlement(oldLitigation);
        } else {
            this.tblLegalLitigationsettlementMapper.updateModifyLitigationSettlement(oldLitigation);
        }
    }

    @Override
    public void removeLitigationSettlement(Integer litigationid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblLegalLitigationsettlementMapper.deleteLitigationId(litigationid);
        } else {
            tblLegalLitigationsettlementMapper.deleteLitigationId(litigationid);
        }
    }

    @Override
    public TblLegalLitigationsettlement findByLitigationid(Integer litigationid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblLegalLitigationsettlementMapper.findByLitigationid(litigationid);
        } else {
            return tblLegalLitigationsettlementMapper.findByLitigationid(litigationid);
        }
    }
}
